Back to course home
0% completed
Vote For New Content
Oracle Hard
Integer to English Words (hard)
Solution: Integer to English Words
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Merge K Sorted Lists (hard)
Solution: Merge K Sorted Lists
Max Points on a Line (hard)
Solution: Max Points on a Line
Sudoku Solver (hard)
Solution: Sudoku Solver
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Remove Nth Node From End of List (Medium)
Solution: Remove Nth Node From End of List
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Validate Binary Search Tree (medium)
Problem Statement
Determine if a given binary tree is a binary search tree (BST). In a BST, for each node:
- All nodes to its left have values less than the node's value.
- All nodes to its right have values greater than the node's value.
Examples
Example 1:
- Input: [5,3,7]
- Expected Output: true
- Justification: The left child of the root (3) is less than the root, and the right child of the root (7) is greater than the root. Hence, it's a BST.
Example 2:
- Input: [5,7,3]
- Expected Output: false
- Justification: The left child of the root (7) is greater than the root, making it invalid.
Example 3:
- Input: [10,5,15,null,null,12,20]
- Expected Output: true
- Justification: Each subtree of the binary tree is a valid binary search tree. So, a whole binary tree is a valid binary search tree.
Constraints:
- The number of nodes in the tree is in the range [1, 104].
- -231</sup <= Node.val <= 231</sup - 1
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Longest Increasing Subsequence
Solution: Validate Binary Search Tree
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself